package com.then.component.login;


import android.os.Build;
import android.text.TextUtils;

import com.blankj.utilcode.util.DeviceUtils;
import com.blankj.utilcode.util.PhoneUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.then.basic.socket.data.ProtocolCode;
import com.then.basic.socket.utils.I366PickUtil;

import timber.log.Timber;

/**
 *
 * Created by longyi on 2016/12/13.
 */

public class LoginParams {
    private int loginType;   // 登陆类型，从LoginUtil中可查得所有的数据
    private String loginToken; // 登陆TOKEN，必须和上面类型对应组合
    private String userPhoneNumber;
    private String userPreferNick;
    private String userPhoneCountryCode; // 两位国家代码，仅在使用手机号登陆时使用
    private static String deviceMac;
    private static String deviceIMSI;
    private static String deviceResolution;
    private static String deviceModel;
    private static String deviceVersion;

    public LoginParams(int loginType, String token, String userPhoneNumber, String userPreferNick) {
        this(loginType, token, userPhoneNumber, userPreferNick, null);
    }

    public LoginParams(int loginType, String token, String userPhoneNumber, String userPreferNick,
                       String userPhoneCountryCode) {
        this.loginType = loginType;
        this.loginToken = token;
        this.userPhoneNumber = TextUtils.isEmpty(userPhoneNumber) ? "" : userPhoneNumber;
        this.userPreferNick = TextUtils.isEmpty(userPreferNick) ? "" : userPreferNick;
        this.userPhoneCountryCode = TextUtils.isEmpty(userPhoneCountryCode) ? "" : userPhoneCountryCode;
        initDeviceInfo();
    }

   public byte[] getRequestData() {

       Timber.d("loginType:"+loginType);
       Timber.d("loginToken:"+loginToken);
       Timber.d("deviceMac:"+deviceMac);
       Timber.d("deviceIMSI:"+deviceIMSI);
       Timber.d("deviceResolution:"+deviceResolution);
       Timber.d("deviceModel:"+deviceModel);
       Timber.d("deviceVersion:"+deviceVersion);
       Timber.d("userPhoneNumber:"+userPhoneNumber);
       Timber.d("userPreferNick:"+userPreferNick);
       Timber.d("userPhoneCountryCode:"+userPhoneCountryCode);



        Object[][] objs = {
                {60, loginType, I366PickUtil.TYPE_INT_1},
                {131, loginToken, I366PickUtil.TYPE_STRING_UTF16},
                {132, deviceMac, I366PickUtil.TYPE_STRING_UTF16},
                {133, deviceIMSI, I366PickUtil.TYPE_STRING_UTF16},
                {134, deviceResolution, I366PickUtil.TYPE_STRING_UTF16},
                {135, deviceModel, I366PickUtil.TYPE_STRING_UTF16},
                {136, deviceVersion, I366PickUtil.TYPE_STRING_UTF16},
                {137, userPhoneNumber, I366PickUtil.TYPE_STRING_UTF16},
                {138, userPreferNick, I366PickUtil.TYPE_STRING_UTF16},
                {139, userPhoneCountryCode, I366PickUtil.TYPE_STRING_UTF16},
        };
        return I366PickUtil.packAll(objs, ProtocolCode.REQ_LOGIN_LOGINSERVER, 0);
    }

    private void initDeviceInfo() {
        if (TextUtils.isEmpty(deviceModel)) {
            deviceMac = DeviceUtils.getMacAddress();
            deviceIMSI= PhoneUtils.getIMSI();
            deviceResolution= ScreenUtils.getScreenHeight()+"*"+ScreenUtils.getScreenWidth();
            deviceModel = Build.BRAND + "_" + Build.MODEL;
            deviceVersion = Build.VERSION.RELEASE;
        }
    }
}
